<template>
  <div class="product-promotion">
    <el-steps  active="2" align-center>
      <el-step title="填写商品信息" icon="el-icon-edit"></el-step>
      <el-step title="填写商品属性" icon="el-icon-price-tag"></el-step>
      <el-step title="添加商品图片" icon="el-icon-picture"></el-step>
      <el-step title="选择商品关联" icon="el-icon-connection"></el-step>
    </el-steps>
    <div class="form-scroll-container">
      <el-form :model="promotionForm" :rules="rules" ref="ruleForm" label-width="120px" class="form-container">
        <el-form-item label="商品计量单位" prop="unit" required>
          <el-input v-model="promotionForm.unit" ></el-input>
        </el-form-item>
        <!-- 商品状态开关 -->
        <el-form-item label="预告商品">
          <div class="switch-container">
            <el-switch v-model="promotionForm.previewStatus"></el-switch>
          </div>
        </el-form-item>

        <el-form-item label="商品上架">
          <div class="switch-container">
            <el-switch v-model="promotionForm.publishStatus"></el-switch>
          </div>
        </el-form-item>

        <!-- 商品推荐 -->
        <el-form-item label="商品推荐">
          <span class="recommendation-group">
            新品 <el-switch v-model="promotionForm.newStatus"></el-switch>
            推荐 <el-switch v-model="promotionForm.recommendStatus"></el-switch>
          </span>
        </el-form-item>
      </el-form>
    </div>

    <div class="button-container">
      <el-button @click="goBack('ruleForm')">上一步，填写商品信息</el-button>
      <el-button type="primary" @click="goNext('ruleForm')">下一步，填写商品属性</el-button>
    </div>
  </div>
</template>

<script>

export default {
  name: 'ProductPromotion',
  data() {
    var validateUnit = (rule, value, callback) => {
      if (!value) {
        callback(new Error('商品名称不能为空'));
      } else if (typeof value !== 'string') {
        callback(new Error('商品名称必须是字符串'));
      } else {
        callback();
      }
    };
    return {
      promotionForm: {
      //计量单位
        unit:'',
      //是否时预告商品
       previewStatus: false,
       //是否上架
       publishStatus: false,
       //是否新品
       newStatus: false,
       //是否推荐
       recommendStatus: false,
    },
    rules:{
        unit:[
          {validator: validateUnit, trigger: 'blur'}
        ]
    },
  }
},

mounted(){
  const data=this.$store.getters['productForm/get_SECOND_tData']
  this.promotionForm=data
},

  methods: {
    goNext(formName) {
      this.$refs[formName].validate((valid) => {
        if(valid){
          this.$store.dispatch('productForm/SET_second_DATA', this.promotionForm)
          this.$router.push('/home/addProduct/productAttribute')
        } else {
          console.log('error submit!!!')
          return false;
        }
      });
    },
    goBack(formName) {
      this.$refs[formName].resetFields();
      this.$router.push('/home/addProduct')
    },
  }
}
</script>

<style scoped>
.product-promotion {
  padding: 30px;
  background: linear-gradient(to bottom, #ffffff, #f8f9fa);
  border-radius: 15px;
  height: calc(100vh - 120px);
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

.page-header {
  text-align: center;
  margin: 30px 0 40px;
}

.page-header h2 {
  color: #2c3e50;
  font-size: 24px;
  margin-bottom: 10px;
}

.subtitle {
  color: #606266;
  font-size: 14px;
}

.form-container {
  margin-top: 30px;
  padding: 20px;
}

.form-scroll-container::-webkit-scrollbar {
  width: 10px;
}

.custom-steps {
  margin-bottom: 40px;
  padding: 20px;
  background: white;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}


:deep(.el-step__title.is-process) {
  color: #409EFF;
  font-weight: 600;
}

:deep(.el-step__head.is-process) {
  border-color: #409EFF;
  color: #409EFF;
}

</style>